<?php

namespace Admin\Model;
use Common\Model\CommonModel;

class TermsModel extends CommonModel{
    protected $tableName = 'terms';
    protected $_validate =array(
        array('name','require','分类名称必填！',1,regex,3),//默认情况下用正则验证
        array('taxonomy','require','分类类型必填！',1,regex,3),//默认情况下用正则验证
    );
    protected $_auto = array(
        array('slug', 'strtolower', self::MODEL_BOTH, 'function'),//别名转换为小写
        array('create_time',NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH), // 对update_time字段在更新的时候写入当前时间戳     );
    );

    //获取文章数
    function term_relation_count($term_id,$table='posts'){
    	$map['term_id']=$term_id;
    	$map['table']=$table;
    	$totalCount= M('term_relationships')->where($map)->count();
    	return $totalCount;
    }

}